package cfca.seal.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtil
{
  public static final String FORMAT_DAT = "yyyy-MM-dd HH:mm:ss";

  public static Date getCurrentTime()
  {
    Calendar calendar = Calendar.getInstance();
    return calendar.getTime();
  }

  public static String getCurrentTimeToString() {
    Calendar calendar = Calendar.getInstance();
    return getTimeInFormat(calendar, "yyyy-MM-dd HH:mm:ss");
  }

  public static String getCurrentTime(String format) {
    Calendar calendar = Calendar.getInstance();
    return getTimeInFormat(calendar, format);
  }

  public static String getFormatDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return getTimeInFormat(calendar, "yyyy-MM-dd HH:mm:ss");
  }

  public static String getTimeInFormat(Calendar calendar, String format) {
    DateFormat df = new SimpleDateFormat(format);
    return df.format(calendar.getTime());
  }

  public static String formatDate(String sDate, String sFmtFrom, String sFmtTo)
  {
    SimpleDateFormat sdfFrom = null;
    SimpleDateFormat sdfTo = null;
    Date dt = null;

    if (sDate == null) {
      return sDate;
    }
    try
    {
      sdfFrom = new SimpleDateFormat(sFmtFrom);
      dt = sdfFrom.parse(sDate);

      sdfTo = new SimpleDateFormat(sFmtTo);

      return sdfTo.format(dt);
    } catch (Exception e) {
    }
    return sDate;
  }
}